package runtest;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * SmartCommonTest4Java.java
 *
 * Created on 2010. 10. 27,  1:47:46
 */
import inas.smart.*;
import java.io.IOException;
import javax.swing.*;
import java.io.InputStream;
import java.awt.Font;
import java.awt.FontFormatException;
import java.io.File;
import org.jdesktop.beansbinding.*;
/**
 *
 * @author inasystem
 */
public class SmartCommonTest4Java extends javax.swing.JFrame {

    /** Creates new form SmartCommonTest4Java */
    public SmartCommonTest4Java() {
        initComponents();

        if (SmartDriver.NoDevice > 0) {
            SmartDriver.close();
        }

        int ret = 0;
        //int nID[] = new int[1];
        //char ID[] = new char[32 * 16];

        //SmartPrinterList spl = new SmartPrinterList();
        //SmartPrinterInfo devInfo = new SmartPrinterInfo();


        //int ret=0;
         ret = SD.jSmartComm_GetDeviceList(SD.SmartPrinterList);
         SmartPrinterList spl = SD.SmartPrinterList;
         SD.NoDevice = spl.n;
        jTextArea1.setText("The number of Printer = " + Integer.toString(SD.NoDevice) + "\n");

        //ret = SD.jSmartComm_GetDeviceList(nID, ID);
        String[] sid = new String[32];
        System.out.print("Number of Printers = " + spl.n + "\n");
        for (int i = 0; i < SD.NoDevice; i++) {
           // sid = new String([i], i * 16, 16);
            //sid[i] = new String(spl.id[i], 0, 16);
            //sid[i] = SD.CopyUntilNullOrSpace(sid[i]);
            sid[i] = SD.CopyUntilNull(spl.id[i]);
            jPrinterComboBoxAddItem(sid[i]);
            System.out.print("Printer ID[" + i + "] = " + sid[i] + "\n");
            //jTextArea1.setText("Printer ID[" + i + "] = " + sid[i] + "\n");
        }


         ret = SD.jSmartComm_OpenDevice(spl.id[0], SD.SMART_OPENDEVICE_BYID);
         SD.handle = ret;
         SD.PrinterID = sid[0];
         //String pDesc = new String(spl.desc[0], 0, 16);
         SD.PrinterDesc = SD.CopyUntilNull(spl.desc[0]);

         System.out.print("Printer ID[0] =" + sid[0] +"is opened, Handle = " + SD.handle + "\n");
         // System.out.print("Printer Description = " + SD.PrinterDesc + "\n");


         //ret = smart.jSmartComm_GetDeviceInfo(devInfo, spl.id[0], smart.SmartCommonConstant.SMART_OPENDEVICE_BYID);
         ret = SD.jSmartComm_GetDeviceInfo(SD.SmartPrinterInfo, spl.id[0], SD.SMART_OPENDEVICE_BYID);
         SmartPrinterInfo devInfo = SD.SmartPrinterInfo;
         jTextArea1.setText(  "     The number of Printer = " + Integer.toString(SD.NoDevice) + "\n"
                            + "     Printer ID - Opened : " + SD.CopyUntilNull(devInfo.id) + "\n"
                            + "     Printer Name      : " + SD.CopyUntilNull(devInfo.name) + "\n"
                            + "     Printer DEV       : " + SD.CopyUntilNull(devInfo.dev) + "\n"
                            + "     Printer Dev_Type  : " + Integer.toString(devInfo.dev_type[0])+ "\n"
                            + "     Printer Pid       : " + Integer.toString(devInfo.pid[0])+ "\n"
                            + "     Printer USB Port  : " + SD.CopyUntilNull(devInfo.usbport) + "\n"
                            + "     Printer TCP Port  : " + Integer.toString(devInfo.tcpport[0])+ "\n"
                            + "     Printer Is_SSL    : " + Integer.toString(devInfo.is_ssl[0])+ "\n"
                            + "     Printer Is_Dual   : " + Integer.toString(devInfo.is_dual[0])+ "\n"
                            + "     Printer Is_Bridge : " + Integer.toString(devInfo.is_bridge[0])+ "\n"
                            + "     Printer ic1       : " + SD.CopyUntilNull(devInfo.ic1) + "\n"
                            + "     Printer ic2       : " + SD.CopyUntilNull(devInfo.ic2) + "\n"
                            + "     Printer rf1       : " + SD.CopyUntilNull(devInfo.rf1) + "\n"
                            + "     Printer rf2       : " + SD.CopyUntilNull(devInfo.rf2) + "\n"
                             );


         
     /*    jTextField1.setText("Printer ID : " + SD.CopyUntilNull(devInfo.id) + "\n\n"
                            + "Printer DEV : " + SD.CopyUntilNull(devInfo.dev) + "\n"
                            + "Printer Dev_Type : " + devInfo.dev_type + "\n"
                  );
*/
         

/*
         System.out.printf("Printer Device Information Name = %s \n", devInfo.name);
         System.out.print("                          ID   = "+ devInfo.id + "\n");
 //        System.out.printf("                          PID  = %d \n", devInfo.pid );
         System.out.print("                       USBPORT = "+ devInfo.usbport + "\n");
         System.out.print("                        IS_SSL = "+ devInfo.is_ssl + "\n");
         System.out.print("                           dev = "+ devInfo.dev + "\n");
         System.out.print("                      dev_type = "+ devInfo.dev_type + "\n");
         System.out.print("                          link = "+ devInfo.link + "\n");
         System.out.print("                       tcpport = "+ devInfo.tcpport + "\n");
         System.out.print("                            ip = "+ devInfo.ip + "\n");
         System.out.print("                       is_dual = "+ devInfo.is_dual + "\n");
         System.out.print("                           ic1 = "+ devInfo.ic1 + "\n");
         System.out.print("                           rf1 = "+ devInfo.rf1 + "\n");
*/

    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
    private void initComponents() {
        bindingGroup = new org.jdesktop.beansbinding.BindingGroup();

        jPanel2 = new javax.swing.JPanel();
        jLabel2 = new javax.swing.JLabel();
        jPrinterComboBox = new javax.swing.JComboBox();
        jCheckBoxSBSMode = new javax.swing.JCheckBox();
        jScrollPane3 = new javax.swing.JScrollPane();
        jTextArea1 = new javax.swing.JTextArea();
        jPanel7 = new javax.swing.JPanel();
        jButtonDCLCsdFilePrint = new javax.swing.JButton();
        jButtonDCLFunctionDrawingPrint = new javax.swing.JButton();
        jButtonDCLDriectDrawingPrint = new javax.swing.JButton();
        jPanel8 = new javax.swing.JPanel();
        jButtonMagneticWriteAndRead = new javax.swing.JButton();
        jButtonGetATR = new javax.swing.JButton();
        jButtonContactlessSmartCard = new javax.swing.JButton();
        jPanel9 = new javax.swing.JPanel();
        jButtonOpenCSDDocument = new javax.swing.JButton();
        jButtonCloseCSDDocument = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTextPane1 = new javax.swing.JTextPane();
        jPanel6 = new javax.swing.JPanel();
        jButtonCSDFilePrint = new javax.swing.JButton();
        jButtonFunctionDrawingPrint = new javax.swing.JButton();
        jButtonDirectDrawingPrint = new javax.swing.JButton();
        jLabel3 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jLabel2.setFont(new java.awt.Font("", 1, 14));
        jLabel2.setText("I&A Smart Printer");

        jPrinterComboBox.setFont(new java.awt.Font("", 1, 14)); // NOI18N

        org.jdesktop.beansbinding.Binding binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, jPrinterComboBox, org.jdesktop.beansbinding.ObjectProperty.create(), jPrinterComboBox, org.jdesktop.beansbinding.BeanProperty.create("elements"));
        bindingGroup.addBinding(binding);

        jPrinterComboBox.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jPrinterComboBoxMouseClicked(evt);
            }
        });
        jPrinterComboBox.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                jPrinterComboBoxItemStateChanged(evt);
            }
        });
        jPrinterComboBox.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jPrinterComboBoxActionPerformed(evt);
            }
        });

        jCheckBoxSBSMode.setText("Use SBS(Step-By-Step) Mode, When Print");
        jCheckBoxSBSMode.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jCheckBoxSBSModeActionPerformed(evt);
            }
        });

        jTextArea1.setColumns(20);
        jTextArea1.setRows(5);
        jScrollPane3.setViewportView(jTextArea1);

        jPanel7.setBorder(javax.swing.BorderFactory.createTitledBorder("DCL Mode"));

        jButtonDCLCsdFilePrint.setText("CSD File Print");
        jButtonDCLCsdFilePrint.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonDCLCsdFilePrintActionPerformed(evt);
            }
        });

        jButtonDCLFunctionDrawingPrint.setText("Function Drawing Print");
        jButtonDCLFunctionDrawingPrint.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonDCLFunctionDrawingPrintActionPerformed(evt);
            }
        });

        jButtonDCLDriectDrawingPrint.setText("Driect Drawing Print");
        jButtonDCLDriectDrawingPrint.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonDCLDriectDrawingPrintActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel7Layout = new javax.swing.GroupLayout(jPanel7);
        jPanel7.setLayout(jPanel7Layout);
        jPanel7Layout.setHorizontalGroup(
            jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel7Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jButtonDCLDriectDrawingPrint, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 158, Short.MAX_VALUE)
                    .addComponent(jButtonDCLFunctionDrawingPrint, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 158, Short.MAX_VALUE)
                    .addComponent(jButtonDCLCsdFilePrint, javax.swing.GroupLayout.DEFAULT_SIZE, 158, Short.MAX_VALUE))
                .addContainerGap())
        );
        jPanel7Layout.setVerticalGroup(
            jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel7Layout.createSequentialGroup()
                .addComponent(jButtonDCLCsdFilePrint)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButtonDCLFunctionDrawingPrint)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButtonDCLDriectDrawingPrint)
                .addContainerGap())
        );

        jPanel8.setBorder(javax.swing.BorderFactory.createTitledBorder("Option Device"));

        jButtonMagneticWriteAndRead.setText("Magnetic Write and Read");
        jButtonMagneticWriteAndRead.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonMagneticWriteAndReadActionPerformed(evt);
            }
        });

        jButtonGetATR.setText("Contact Smart Card(Get ATR)");
        jButtonGetATR.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonGetATRActionPerformed(evt);
            }
        });

        jButtonContactlessSmartCard.setText("Contactless Smart Card - Mifare W/R using PC/SC");
        jButtonContactlessSmartCard.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonContactlessSmartCardActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel8Layout = new javax.swing.GroupLayout(jPanel8);
        jPanel8.setLayout(jPanel8Layout);
        jPanel8Layout.setHorizontalGroup(
            jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel8Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addComponent(jButtonContactlessSmartCard, javax.swing.GroupLayout.Alignment.LEADING, 0, 0, Short.MAX_VALUE)
                    .addComponent(jButtonMagneticWriteAndRead, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jButtonGetATR, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 358, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(19, Short.MAX_VALUE))
        );
        jPanel8Layout.setVerticalGroup(
            jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel8Layout.createSequentialGroup()
                .addComponent(jButtonMagneticWriteAndRead)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButtonGetATR)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButtonContactlessSmartCard)
                .addContainerGap())
        );

        jPanel9.setBorder(javax.swing.BorderFactory.createTitledBorder("CSD Document"));

        jButtonOpenCSDDocument.setText("Open CSD Document");
        jButtonOpenCSDDocument.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonOpenCSDDocumentActionPerformed(evt);
            }
        });

        jButtonCloseCSDDocument.setText("Close CSD Document");
        jButtonCloseCSDDocument.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonCloseCSDDocumentActionPerformed(evt);
            }
        });

        jScrollPane1.setViewportView(jTextPane1);

        javax.swing.GroupLayout jPanel9Layout = new javax.swing.GroupLayout(jPanel9);
        jPanel9.setLayout(jPanel9Layout);
        jPanel9Layout.setHorizontalGroup(
            jPanel9Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel9Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel9Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 365, Short.MAX_VALUE)
                    .addGroup(jPanel9Layout.createSequentialGroup()
                        .addComponent(jButtonOpenCSDDocument, javax.swing.GroupLayout.PREFERRED_SIZE, 188, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(jButtonCloseCSDDocument, javax.swing.GroupLayout.DEFAULT_SIZE, 159, Short.MAX_VALUE)))
                .addContainerGap())
        );
        jPanel9Layout.setVerticalGroup(
            jPanel9Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel9Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel9Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jButtonOpenCSDDocument)
                    .addComponent(jButtonCloseCSDDocument))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 68, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jPanel6.setBorder(javax.swing.BorderFactory.createTitledBorder("Driver Mode"));

        jButtonCSDFilePrint.setText("CSD File Print");
        jButtonCSDFilePrint.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonCSDFilePrintActionPerformed(evt);
            }
        });

        jButtonFunctionDrawingPrint.setText("Function Drawing Print");
        jButtonFunctionDrawingPrint.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonFunctionDrawingPrintActionPerformed(evt);
            }
        });

        jButtonDirectDrawingPrint.setText("Driect Drawing Print");
        jButtonDirectDrawingPrint.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonDirectDrawingPrintActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel6Layout = new javax.swing.GroupLayout(jPanel6);
        jPanel6.setLayout(jPanel6Layout);
        jPanel6Layout.setHorizontalGroup(
            jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel6Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jButtonCSDFilePrint, javax.swing.GroupLayout.DEFAULT_SIZE, 160, Short.MAX_VALUE)
                    .addComponent(jButtonFunctionDrawingPrint, javax.swing.GroupLayout.DEFAULT_SIZE, 160, Short.MAX_VALUE)
                    .addComponent(jButtonDirectDrawingPrint, javax.swing.GroupLayout.DEFAULT_SIZE, 160, Short.MAX_VALUE))
                .addContainerGap())
        );
        jPanel6Layout.setVerticalGroup(
            jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel6Layout.createSequentialGroup()
                .addComponent(jButtonCSDFilePrint)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButtonFunctionDrawingPrint)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButtonDirectDrawingPrint))
        );

        jLabel3.setText("Opened Smart Printer Information");

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGap(10, 10, 10)
                        .addComponent(jCheckBoxSBSMode))
                    .addComponent(jPanel8, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(jPanel6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jPanel7, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 153, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jPrinterComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, 162, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jPanel9, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addGap(18, 18, 18)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 220, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 277, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(29, 29, 29))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                        .addGap(17, 17, 17)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jPrinterComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addComponent(jCheckBoxSBSMode)
                        .addGap(6, 6, 6))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jPanel6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jPanel7, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addComponent(jPanel8, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jPanel9, javax.swing.GroupLayout.PREFERRED_SIZE, 140, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                        .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 369, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(17, 17, 17)))
                .addContainerGap())
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(17, Short.MAX_VALUE)
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        bindingGroup.bind();

        pack();
    }// </editor-fold>                        

    private void jButtonDirectDrawingPrintActionPerformed(java.awt.event.ActionEvent evt) {                                                          
        // TODO add your handling code here:
}                                                         

    private void jButtonFunctionDrawingPrintActionPerformed(java.awt.event.ActionEvent evt) {                                                            
        // TODO add your handling code here:

        // acquire selected printer id.
        String PrinterID = SD.getDeviceListID(0);
        // open device...

        int nres = SC.SM_SUCCESS;
        if (nres == SC.SM_SUCCESS) {
            nres = SD.jSmartComm_OpenDevice(PrinterID);
        }
        // open device...
        if (nres == SC.SM_SUCCESS) {
            nres = SD.jSmartComm_OpenDevice(SD.PrinterID);
        }

        // get status...
        long uis[] = new long[1];
        boolean bHasRot = false;
        if (nres == SC.SM_SUCCESS) {
            nres = SD.jSmartComm_GetStatus(SD.handle, uis);
        }
        if (nres == SC.SM_SUCCESS) {
            if ((uis[0] & SC.SMSC_S_EQUIPROTATOR) > 0) {
                bHasRot = true;
            } else {
                bHasRot = false;
            }
        }

        // get current printer setting...
        CHASM_DEVMODE dm = new CHASM_DEVMODE();
        if (nres == SC.SM_SUCCESS) {
            nres = SD.jSmartComm_GetPrinterSettings(SD.handle, dm);
        }
        if (nres == SC.SM_SUCCESS) {
            if (bHasRot) {
                dm.dwDocPrintSide = SC.SMART_PRINTSIDE_BOTH;
            } else {
                dm.dwDocPrintSide = SC.SMART_PRINTSIDE_FRONT;
            }
        }
        if (nres == SC.SM_SUCCESS) {
            nres = SD.jSmartComm_SetPrinterSettings(SD.handle, dm);
        }

        // start SBS mode
        if (nres == SC.SM_SUCCESS
                && bUseSBS) {
            nres = SD.jSmartComm_SBSStart(SD.handle);
        }

        // insert card
        if (nres == SC.SM_SUCCESS && bUseSBS) {
            nres = SD.jSmartComm_CardIn(SD.handle);
        }

        RECT rc = new RECT();
        char char_szurl[] = new char[1024];
        String szurl = new File(".").getAbsolutePath();
        szurl = szurl + File.separator + "bkgnd.bmp";

        char_szurl = szurl.toCharArray();
        // draw...
        if (nres == SC.SM_SUCCESS) {
            nres = SD.jSmartComm_DrawImage(SD.handle, SC.PAGE_FRONT, SC.PANELID_COLOR,
                    0, 0, 0, 0, char_szurl, rc);
        }
        if (nres == SC.SM_SUCCESS) {
            nres = SD.jSmartComm_DrawText(SD.handle, SC.PAGE_FRONT, SC.PANELID_BLACK,
                    20, 60, "Tahoma".toCharArray(), -60, SC.FONT_BOLD,
                    "SMART DCL Test !!!".toCharArray(), rc);
        }
        if (nres == SC.SM_SUCCESS) {
            nres = SD.jSmartComm_DrawText(SD.handle, SC.PAGE_BACK, SC.PANELID_BLACK,
                    20, 60, "Tahoma".toCharArray(), -30, SC.FONT_BOLD,
                    "SMART DCL Test !!!".toCharArray(), rc);
        }

        // print to device...
        if (nres == SC.SM_SUCCESS) {
            nres = SD.jSmartComm_Print(SD.handle);
        }

        // print start front page...
        if (nres == SC.SM_SUCCESS && bUseSBS) {
            nres = SD.jSmartComm_DoPrint(SD.handle);
        }
        // print start back page...
        if (nres == SC.SM_SUCCESS && bUseSBS && bHasRot) {
            nres = SD.jSmartComm_DoPrint(SD.handle);
        }


        // card out, if under SBS mode...
        if (bUseSBS) {
            SD.jSmartComm_CardOut(SD.handle);
        }

        // end SBS mode...
        if (bUseSBS) {
            nres = SD.jSmartComm_SBSEnd(SD.handle);
        }

        // close device...

        if (true) {
            nres = SD.jSmartComm_CloseDevice(SD.handle);
        }

        if (nres != SC.SM_SUCCESS) {
            ShowDialogBox("ERROR", "ERROR 1002 : Function Drawing Print" + nres);
            return;
        }
}                                                           

    private void jButtonCSDFilePrintActionPerformed(java.awt.event.ActionEvent evt) {                                                    
        // TODO add your handling code here:
        String PrinterID = SD.getDeviceListID(0);
        // open device...

        int nres = SC.SM_SUCCESS;
        if (nres == SC.SM_SUCCESS) {
            nres = SD.jSmartComm_OpenDevice(PrinterID);
        }

        // start SBS mode
        if (nres == SC.SM_SUCCESS && bUseSBS) {
            nres = SD.jSmartComm_SBSStart(SD.handle);
        }

        // insert card
        if (nres == SC.SM_SUCCESS && bUseSBS) {
            nres = SD.jSmartComm_CardIn(SD.handle);
        }

        // open .csd document...
        //	test.csd is a single paged document.

        String szurl = new File(".").getAbsolutePath();
        szurl = szurl + File.separator + "test2.csd";
        if (nres == SC.SM_SUCCESS) {
            nres = SD.jSmartComm_OpenDocument(SD.handle, szurl);
        }

        // print to device...
        if (nres == SC.SM_SUCCESS) {
            nres = SD.jSmartComm_Print(SD.handle);
        }

        // print start front page...
        if (nres == SC.SM_SUCCESS
                && bUseSBS) {
            nres = SD.jSmartComm_DoPrint(SD.handle);
        }

        // close opened document.
        if (nres == SC.SM_SUCCESS) {
            nres = SD.jSmartComm_CloseDocument(SD.handle);
        }

        // card out, if under SBS mode...
        if (bUseSBS) {
            SD.jSmartComm_CardOut(SD.handle);
        }

        // end SBS mode...
        if (bUseSBS) {
            nres = SD.jSmartComm_SBSEnd(SD.handle);
        }

        // close device...
        nres = SD.jSmartComm_CloseDevice(SD.handle);

        if (nres != SC.SM_SUCCESS) {
            ShowDialogBox("ERROR", "1001 : CSD File Print, ret=" + nres);
            return;
        }
}                                                   

    private void jButtonCloseCSDDocumentActionPerformed(java.awt.event.ActionEvent evt) {                                                        
        // TODO add your handling code here:
}                                                       

    private void jButtonOpenCSDDocumentActionPerformed(java.awt.event.ActionEvent evt) {                                                       
        // TODO add your handling code here:
}                                                      

    private void jButtonContactlessSmartCardActionPerformed(java.awt.event.ActionEvent evt) {                                                            
        // TODO add your handling code here:
        String strID;
        int nres = SC.SM_SUCCESS;
        byte btATR[] = new byte[64];
        btATR[0] = 0x00;
        long nATRLen[] = new long[1];
        nATRLen[0] = 64;
        int nCardType[] = new int[1];
        nCardType[0] = SC.RFTYPEUNSET;
        boolean bRFPCSC = false;

        byte btCmd[] = new byte[300];
        btCmd[0] = 0;
        byte btRcv[] = new byte[300];
        btRcv[0] = 0;
        int nlencmd = 0;
        long nlenrcv[] = new long[1];
        nlenrcv[0] = 300;
        boolean bAPDURes = true;

        byte btWrite[] = new byte[16];
        btWrite[0] = 0x30;
        btWrite[0] = 0x31;
        btWrite[0] = 0x32;
        btWrite[0] = 0x33;
        btWrite[0] = 0x34;
        btWrite[5] = 0x35;
        btWrite[6] = 0x36;
        btWrite[7] = 0x37;
        btWrite[8] = 0x38;
        btWrite[9] = 0x39;
        btWrite[10] = 0x30;
        btWrite[11] = 0x31;
        btWrite[12] = 0x32;
        btWrite[13] = 0x33;
        btWrite[14] = 0x34;
        btWrite[15] = 0x35;

        // acquire selected device id

        // acquire selected device id
        String PrinterID = SD.getDeviceListID(0);

        if (SC.SM_SUCCESS == nres) {
            nres = SD.jSmartComm_OpenDevice(PrinterID);
        }
        if (SC.SM_SUCCESS == nres) {
            nres = SD.jSmartComm_SBSStart(SD.handle);
        }
        if (SC.SM_SUCCESS == nres) {
            nres = SD.jSmartComm_CardIn(SD.handle);
        }
        if (SC.SM_SUCCESS == nres) {
            nres = SD.jSmartComm_Move(SD.handle, SC.CARDPOS_RF2);
        }

        if (SC.SM_SUCCESS == nres) {
            nres = SD.jSmartComm_RFPowerOn(SD.handle, DEV_IC, nCardType, nATRLen, btATR);
        }

        if (nres == SC.SM_SUCCESS) {
            String strATR;
            bRFPCSC = (nATRLen[0] > 4);

            strATR = "ATR : ";
            String strHex = null;
            for (int i = 0; i < nATRLen[0]; i++) {

                try {
                    strHex.concat(hex((int) (btATR[i] & 0xff), 2));
                    //      strHex = String.format( Locale.getDefault(), "%02x", a[0] );
                } catch (NullPointerException e) {
                    ;
                }
            }
            ShowDialogBox("MSG ", strATR);
        }

        // get CSN(Chip Serial Number)
        //
        if (nres == SC.SM_SUCCESS) {
            nlenrcv[0] = btRcv.length;
            nlencmd = 0;

            btCmd[nlencmd++] = (byte) 0xFF;	//CLA
            btCmd[nlencmd++] = (byte) 0xCA;	//INS
            btCmd[nlencmd++] = (byte) 0x00;	//P1
            btCmd[nlencmd++] = (byte) 0x00;	//P2
            btCmd[nlencmd++] = (byte) 0x00;	//Le

            nres = SD.jSmartComm_RFOutput(SD.handle, DEV_INTERNALRF, nlencmd, btCmd, nlenrcv, btRcv);
        }
        if (nres == SC.SM_SUCCESS) {
            String strUID = "CSN : ";
            String strHex = null;
            for (int i = 0; i < nlenrcv[0] - 2; i++) {
                //        strHex.Format("%02X ", (BYTE) btATR[i]);
                strHex.concat(hex((int) (btATR[i] & 0xff), 2));
                strHex.concat(" ");
            }
            ShowDialogBox("MSG", "MSG 1003 : strUID = " + strHex);
        }


        // load key to reader...
        //
        if (nres == SC.SM_SUCCESS) {
            nlenrcv[0] = btRcv.length;
            nlencmd = 0;

            btCmd[nlencmd++] = (byte) 0xFF;	// CLA
            btCmd[nlencmd++] = (byte) 0x82;	// INS
            btCmd[nlencmd++] = (byte) 0x20;	// P1, card key, plain tramsmission, non-volatile memory
            btCmd[nlencmd++] = (byte) 0x00;	// P2, Key Number for mifare could be 0x00 to 0x31
            btCmd[nlencmd++] = 6;	// Lc, Key Length
            //      memcpy(btCmd + nlencmd, "\xFF\xFF\xFF\xFF\xFF\xFF", 6);
            nlencmd += 6;

            nres = SD.jSmartComm_RFInput(SD.handle, DEV_INTERNALRF, nlencmd, btCmd, nlenrcv, btRcv);
        }
        if (nres == SC.SM_SUCCESS) {
            //      bAPDURes = (*  (btRcv + nlenrcv[0] - 2) == 0x90 && *  (btRcv + nlenrcv[0] - 1) == 0x00);
        }


        // auth...
        //
        if (nres == SC.SM_SUCCESS && bAPDURes) {
            nlenrcv[0] = btRcv.length;
            nlencmd = 0;

            btCmd[nlencmd++] = (byte) 0xFF;	// CLA
            btCmd[nlencmd++] = (byte) 0x88;	// INS
            btCmd[nlencmd++] = 0x00;	// P1, Mifare Block Number MSB, for mifare it is always 0x00
            btCmd[nlencmd++] = 3;	// P2, Block No.
            btCmd[nlencmd++] = (byte) SC.MIFARE_AUTHENT1A;	 // // P3, Key Type
            btCmd[nlencmd++] = 0x00;	//  Key Number

            nres = SD.jSmartComm_RFInput(SD.handle, DEV_INTERNALRF, nlencmd, btCmd, nlenrcv, btRcv);
        }
        if (nres == SC.SM_SUCCESS && bAPDURes) {
            //     bAPDURes = (*  (btRcv + nlenrcv - 2) == 0x90 && *  (btRcv + nlenrcv - 1) == 0x00);
        }


        // write...
        //
        if (nres == SC.SM_SUCCESS
                && bAPDURes) {
            nlenrcv[0] = btRcv.length;
            nlencmd = 0;

            btCmd[nlencmd++] = (byte) 0xFF;	// CLA
            btCmd[nlencmd++] = (byte) 0xD6;	// INS
            btCmd[nlencmd++] = 0x00;	// P1, Mifare Block Number MSB, for mifare it is always 0x00
            btCmd[nlencmd++] = 2;	// P2, Mifare Block Number LSB
            btCmd[nlencmd++] = 16;	// Lc, Data Length
            //  memcpy(btCmd + nlencmd, btWrite, 16);
            nlencmd += 16;

            nres = SD.jSmartComm_RFInput(SD.handle, DEV_INTERNALRF, nlencmd, btCmd, nlenrcv, btRcv);
        }
        if (nres == SC.SM_SUCCESS && bAPDURes) {
            //          bAPDURes = (*  (btRcv + nlenrcv - 2) == 0x90   && *  (btRcv + nlenrcv - 1) == 0x00);
            ; // MORE
        }


        // read...
        //
        if (nres == SC.SM_SUCCESS && bAPDURes) {
            nlenrcv[0] = btRcv.length;
            nlencmd = 0;

            btCmd[nlencmd++] = (byte) 0xFF;	// CLA
            btCmd[nlencmd++] = (byte) 0xB0;	// INS
            btCmd[nlencmd++] = 0x00;	// P1, Mifare Block Number MSB, for mifare it is always 0x00
            btCmd[nlencmd++] = 2;	// P2, Mifare Block Number LSB
            btCmd[nlencmd++] = 16;	// Le, read size
            //    public int jSmartComm_RFOutput(int hHandle, int nDev, long dwInLen, byte[] pInBuf,
            //            long[] pdwOutLen, byte[] pOutBuf) {
            nres = SD.jSmartComm_RFOutput(SD.handle, DEV_INTERNALRF, (long) nlencmd, btCmd, nlenrcv, btRcv);
        }
        if (nres == SC.SM_SUCCESS && bAPDURes) {
            //    bAPDURes = (*  (btRcv + nlenrcv - 2) == 0x90 && *  (btRcv + nlenrcv - 1) == 0x00);
            ; // MORE ...
        }


        // verify...
        //
        if (nres == SC.SM_SUCCESS && bAPDURes) {
            if (memcmp(btWrite, btRcv, 16) != 0) {
                ShowDialogBox("ERROR", "Data is Differs from Write and Read..");
            }
        }


        if (nres == SC.SM_SUCCESS) {
            SD.jSmartComm_RFPowerOff(SD.handle, DEV_INTERNALRF);
        }


        if (true) {
            SD.jSmartComm_CardOut(SD.handle);
        }
        if (true) {
            SD.jSmartComm_SBSEnd(SD.handle);
        }
        if (true) {
            SD.jSmartComm_CloseDevice(SD.handle);
        }


        if (nres != SC.SM_SUCCESS) {
            ShowDialogBox("ERROR", "ERROR 1003 : " + nres);
        }

    }                                                           

    private void jButtonGetATRActionPerformed(java.awt.event.ActionEvent evt) {                                              
        // TODO add your handling code here:
        String PrinterID = SD.getDeviceListID(0);
        // open device...

        int nres = SC.SM_SUCCESS;
        if (nres == SC.SM_SUCCESS) {
            nres = SD.jSmartComm_OpenDevice(PrinterID);
        }

        byte btATR[] = new byte[64];
        long nATRLen[] = new long[1];
        nATRLen[0] = 64;
        String strATR;

        if (SC.SM_SUCCESS == nres) {
            nres = SD.jSmartComm_OpenDevice(PrinterID);
        }
        if (SC.SM_SUCCESS == nres) {
            nres = SD.jSmartComm_SBSStart(SD.handle);
        }
        if (SC.SM_SUCCESS == nres) {
            nres = SD.jSmartComm_CardIn(SD.handle);
        }
        if (SC.SM_SUCCESS == nres) {
            nres = SD.jSmartComm_Move(SD.handle, SC.CARDPOS_IC);
        }

        if (SC.SM_SUCCESS == nres) {
            nres = SD.jSmartComm_ICHContact(SD.handle);
        }

        if (SC.SM_SUCCESS == nres) {
            nres = SD.jSmartComm_ICPowerOn(SD.handle, DEV_IC, nATRLen, btATR);
        }
        if (nres == SmartCommConstant.SM_SUCCESS) {
            strATR = "ATR : ";
            String strHex = null;
            for (int i = 0; i < nATRLen[0]; i++) {
                //        strHex.Format("%02X ", (BYTE) btATR[i]);
                strHex.concat(hex((int) (btATR[i] & 0xff), 2));
                strHex.concat(" ");
            }
            ShowDialogBox("MSG", "strATR : [" + strATR);
        }
        if (true) {
            SD.jSmartComm_ICPowerOff(SD.handle, DEV_IC);
        }

        if (true) {
            SD.jSmartComm_CardOut(SD.handle);
        }
        if (true) {
            SD.jSmartComm_SBSEnd(SD.handle);
        }
        if (true) {
            SD.jSmartComm_CloseDevice(SD.handle);
        }

        if (nres != SmartCommConstant.SM_SUCCESS) {
            ShowDialogBox("ERROR ", "ERROR 1009 : GetATR : " + nres);
        }
    }                                             

    private void jButtonMagneticWriteAndReadActionPerformed(java.awt.event.ActionEvent evt) {                                                            
        // TODO add your handling code here:
        String strID;
        char btT1[] = new char[SC.MAG_T1MAX + 1];
        btT1 = "3517905691800546673562220499609360194040016728006751762622542504817260791961".toCharArray();
        char btT2[] = new char[SC.MAG_T3MAX + 1];
        char btT3[] = new char[SC.MAG_T3MAX + 1];
        btT3 = "27343498214459629968794339285425411314365162987832449000079862737616503964094360730000764808352901543030".toCharArray();
        char btT1Read[] = new char[SC.MAG_T1MAX + 1];
        char btT2Read[] = new char[SC.MAG_T3MAX + 1];
        char btT3Read[] = new char[SC.MAG_T3MAX + 1];
        int nT1ReadLen[] = new int[1];
        nT1ReadLen[0] = SC.MAG_T1MAX;
        int nT2ReadLen[] = new int[1];
        nT2ReadLen[0] = SC.MAG_T1MAX;
        int nT3ReadLen[] = new int[1];
        nT3ReadLen[0] = SC.MAG_T1MAX;
        int nres = SC.SM_SUCCESS;


        // acquire selected device id
        String PrinterID = SD.getDeviceListID(0);


        if (SC.SM_SUCCESS == nres) {
            SD.handle = SD.jSmartComm_OpenDevice(PrinterID);
        }
        if (SC.SM_SUCCESS == nres) {
            nres = SD.jSmartComm_SBSStart(SD.handle);
        }
        if (SC.SM_SUCCESS == nres) {
            nres = SD.jSmartComm_CardIn(SD.handle);
        }

        if (SC.SM_SUCCESS == nres) {
            nres = SD.jSmartComm_MagSetAllBuffer(SD.handle,
                    true, btT1, btT1.length,
                    false, btT2Read, btT2.length,
                    true, btT3, btT3.length);
        }
        if (SC.SM_SUCCESS == nres) {
            nres = SD.jSmartComm_MagWriteAction(SD.handle,
                    SC.MAG_T1 | SC.MAG_T3,
                    false);
        }
        if (SC.SM_SUCCESS == nres) {
            nres = SD.jSmartComm_MagReadAction(SD.handle,
                    SC.MAG_T1 | SC.MAG_T3);
        }
        if (SC.SM_SUCCESS == nres) {
            nres = SD.jSmartComm_MagGetAllBuffer(SD.handle,
                    true, btT1Read, nT1ReadLen,
                    false, btT2Read, nT2ReadLen,
                    true, btT3Read, nT3ReadLen);
        }


        if (true) {
            SD.jSmartComm_CardOut(SD.handle);
        }
        if (true) {
            SD.jSmartComm_SBSEnd(SD.handle);
        }

        if (true) {
            SD.jSmartComm_CloseDevice(SD.handle);
        }


        if (nres != SC.SM_SUCCESS) {
            ShowDialogBox("ERROR ", "ERROR 1003 : " + nres);
        }
}                                                           

    private void jButtonDCLDriectDrawingPrintActionPerformed(java.awt.event.ActionEvent evt) {                                                             
        // TODO add your handling code here:

        // open device...

        int nres = SC.SM_SUCCESS;

        long uis[] = new long[1];
        boolean bHasRot = false;	// flag for rotator is installed.

        String strID;
        SMART_SURFACE pFront = new SMART_SURFACE();
        SMART_SURFACE pBack = new SMART_SURFACE();

        // acquire selected printer id.
        String PrinterID = SD.getDeviceListID(0);

        // open device...
        if (nres == SC.SM_SUCCESS) {
            //       nres = SD.jSmartDCL_OpenDevice(SD.PrinterID, SC.DMORIENT_LANDSCAPE);
        }

        // get status...
        if (nres == SC.SM_SUCCESS) {
            nres = SD.jSmartComm_GetStatus(SD.handle, uis);
        }

        if ((uis[0] & SC.SMSC_S_EQUIPROTATOR) == SC.SMSC_S_EQUIPROTATOR) {
            bHasRot = false;
        } else {
            bHasRot = true;
        }
        // start SBS mode
        if (nres == SC.SM_SUCCESS && bUseSBS) {
            nres = SD.jSmartComm_SBSStart(SD.handle);
        }
        // insert card...
        if (nres == SC.SM_SUCCESS && bUseSBS) {
            nres = SD.jSmartComm_CardIn(SD.handle);
        }
        // get smart-surface...
        if (nres == SC.SM_SUCCESS) {
            nres = SD.jSmartDCL_GetSurface(SD.handle, pFront, pBack);
        }
        // draw...
        if (nres == SC.SM_SUCCESS) {
            String fontFileName = "Tahoma.ttf";
            InputStream is = this.getClass().getResourceAsStream(fontFileName);
            try {
                java.awt.Font ttfBase = Font.createFont(Font.TRUETYPE_FONT, is);
                Font ttfReal = ttfBase.deriveFont(Font.BOLD, 24);
            } catch (FontFormatException e) {
                ;
            } catch (IOException e) {
                ;
            }

            //            HFONT hfnt = ::CreateFont( 60, 0, 0, 0, FW_BOLD, 0, 0, 0, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS,
            //                    NONANTIALIASED_QUALITY, // prevent diffusion-dither
            //                    DEFAULT_PITCH | FF_DONTCARE, _T("Tahoma"));

            //             SelectObject( pFront- > bmp.hdcResin, hfnt);
            pFront.hdcResin = 1;
            pFront.hdcResin = 0;
            //            :: SetTextColor(  pFront- > bmp.hdcResin, RGB(0x00, 0x00, 0x00));

            // draw text on Resin panel...
            RECT rc = new RECT();
            //          rc.setLeft(20);
            //          rc.setRight(20);
            //         rc.setTop(20);
            //        rc.setBottom(20);
            /*
            SD.jSmartComm_DrawText(nres, page, panel, nres, nres,
            szFontName, nres, nFontStyle, "SMART DCL Test", rc);
            DrawText( pFront- > bmp.hdcResin, _T("SMART DCL Test"), -1,  rc,  DT_SINGLELINE |  DT_LEFT | DT_TOP |  DT_NOPREFIX | DT_NOCLIP);

            // draw image on Color panel...
            char szurl[] = new char[1024];
            GetPath( szurl, sizeof(szurl)/sizeof(szurl[0]));
            lstrcat(szurl, _T("bkgnd.bmp"));
            String	szurl  = new File(".").getAbsolutePath();
            szurl = szurl + File.separator + "test.csd";
             *
            HBITMAP hImg = (HBITMAP) LoadImage( theApp.m_hInstance,  szurl, IMAGE_BITMAP,  0, 0, LR_LOADFROMFILE | LR_CREATEDIBSECTION);
            if (hImg != null) {
            DIBSECTION dib;
            BITMAPINFO bi;

            ::GetObject( hImg, sizeof(dib),  & dib);
            bi.bmiHeader = dib.dsBmih;
            :: SetDIBitsToDevice( Front- > bmp.hdcColor,  0, 0,  pFront ->  prop.width, pFront ->  prop.height,
                        0, 0, 0,  dib.dsBm.bmHeight, dib.dsBm.bmBits,  &  bi, DIB_RGB_COLORS);
            DeleteObject(hImg);
            }

            if (pBack && bHasRot) {
            HFONT hfnt = :
            :CreateFont(	30, 0, 0, 0,
            FW_BOLD, 0, 0, 0,
            DEFAULT_CHARSET,
            OUT_DEFAULT_PRECIS,
            CLIP_DEFAULT_PRECIS,
            NONANTIALIASED_QUALITY, // prevent diffusion-dither
            DEFAULT_PITCH | FF_DONTCARE,
            _T("Tahoma"));
            if (hfnt) {
            :: SelectObject( pBack- > bmp.hdcResin, hfnt);
            }
            :: SetTextColor( pBack- > bmp.hdcResin, RGB(0x00, 0x00, 0x00));

            // draw text on Resin panel...
            RECT rc = new RECT();
            rc.setLeft(20);
            rc.setRight(20);
            rc.setTop(20);
            rc.setBottom(20);

            DrawText( pBack- > bmp.hdcResin, _T("SMART DCL Test"), -1,
            &  rc, DT_SINGLELINE | DT_LEFT | DT_TOP | DT_NOPREFIX | DT_NOCLIP);

            if (hfnt) {
            DeleteObject(hfnt);
            hfnt = null;
            }
            }
            }
             */

            // print to device...
            if (nres == SC.SM_SUCCESS) {
                nres = SD.jSmartDCL_Print(SD.handle, bHasRot ? SC.SMART_PRINTSIDE_BOTH : SC.SMART_PRINTSIDE_FRONT);
            }


            // print start front page...
            if (nres == SC.SM_SUCCESS && bUseSBS) {
                nres = SD.jSmartComm_DoPrint(SD.handle);
            }
            // print start back page...
            if (nres == SC.SM_SUCCESS && bUseSBS && bHasRot) {
                nres = SD.jSmartComm_DoPrint(SD.handle);
            }

            // clear opened document and created objects.
            if (nres == SC.SM_SUCCESS) {
                nres = SD.jSmartComm_CloseDocument(SD.handle);
            }

            // card out, if under SBS mode...
            if (bUseSBS) {
                SD.jSmartComm_CardOut(SD.handle);
            }

            // end SBS mode...
            if (bUseSBS) {
                SD.jSmartComm_SBSEnd(SD.handle);
            }

            // close device...
            if (true) {
                SD.jSmartDCL_CloseDevice(SD.handle);
            }

            if (nres != SC.SM_SUCCESS) {
                ShowDialogBox("ERROR", "ERROR 1002 : DCL Driect Drawing Print" + nres);
                return;
            }
        }
}                                                            

    private void jButtonDCLFunctionDrawingPrintActionPerformed(java.awt.event.ActionEvent evt) {                                                               
        // TODO add your handling code here:
        int nres = SC.SM_SUCCESS;
        long uis[] = new long[1];
        boolean bHasRot = false;	// flag for rotator is installed.

        String strID;

        // acquire selected printer id.
        strID = SD.getDeviceListID(0);

        // open device...
        if (nres == SC.SM_SUCCESS) {
            //        nres = SD.jSmartDCL_OpenDevice(strID, SC.DMORIENT_LANDSCAPE);
        }

        // get status...
        if (nres == SC.SM_SUCCESS) {
            nres = SD.jSmartComm_GetStatus(SD.handle, uis);
        }

        if ((uis[0] & SC.SMSC_S_EQUIPROTATOR) == SC.SMSC_S_EQUIPROTATOR) {
            bHasRot = false;
        } else {
            bHasRot = true;
        }

        // start SBS mode
        if (nres == SC.SM_SUCCESS
                && bUseSBS) {
            nres = SD.jSmartComm_SBSStart(SD.handle);
        }

        // insert card
        if (nres == SC.SM_SUCCESS
                && bUseSBS) {
            nres = SD.jSmartComm_CardIn(SD.handle);
        }

        RECT rc = new RECT();
        //      rc.init();
        String szurl = new File(".").getAbsolutePath();
        szurl = szurl + File.separator + "bkgnd.bmp";
        char char_szurl[] = new char[1024];

        char_szurl = szurl.toCharArray();
        // draw...
        if (nres == SC.SM_SUCCESS) {
            nres = SD.jSmartComm_DrawImage(SD.handle,
                    SC.PAGE_FRONT, SC.PANELID_COLOR, 0, 0, 0, 0, char_szurl, rc);
        }
        if (nres == SC.SM_SUCCESS) {
            nres = SD.jSmartComm_DrawText(SD.handle, SC.PAGE_FRONT, SC.PANELID_BLACK,
                    20, 60, "Tahoma".toCharArray(), -60, SC.FONT_BOLD, "SMART DCL Test !!!".toCharArray(), rc);
        }
        if (nres == SC.SM_SUCCESS && bHasRot) {
            nres = SD.jSmartComm_DrawText(SD.handle, SC.PAGE_BACK, SC.PANELID_BLACK, 20, 60,
                    "Tahoma".toCharArray(), -30, SC.FONT_BOLD, "SMART DCL Test !!!".toCharArray(), rc);
        }

        // print to device...
        if (nres == SC.SM_SUCCESS) {
            nres = SD.jSmartDCL_Print(SD.handle, bHasRot ? SC.SMART_PRINTSIDE_BOTH : SC.SMART_PRINTSIDE_FRONT);
        }

        // print start front page...
        if (nres == SC.SM_SUCCESS && bUseSBS) {
            nres = SD.jSmartComm_DoPrint(SD.handle);
        }
        // print start back page...
        if (nres == SC.SM_SUCCESS && bUseSBS && bHasRot) {
            nres = SD.jSmartComm_DoPrint(SD.handle);
        }

        // card out, if under SBS mode...
        if (bUseSBS) {
            SD.jSmartComm_CardOut(SD.handle);
        }

        // end SBS mode...
        if (bUseSBS) {
            SD.jSmartComm_SBSEnd(SD.handle);
        }

        // close device...
        if (true) {
            SD.jSmartDCL_CloseDevice(SD.handle);
        }

        if (nres != SmartCommConstant.SM_SUCCESS) {
            ShowDialogBox("ERROR", "ERROR 1005 : DCL Function Drawing Print :" + nres);
            return;
        }
    }                                                              

    private void jButtonDCLCsdFilePrintActionPerformed(java.awt.event.ActionEvent evt) {                                                       
        // TODO add your handling code here:
        int nres = SC.SM_SUCCESS;
        long uis[] = new long[1];
        boolean bHasRot = false;	// flag for rotator is installed.

        String strID;

        // acquire selected printer id.
        strID = SD.getDeviceListID(0);
        // open device...
        if (nres == SC.SM_SUCCESS) {
            //           nres = SD.jSmartDCL_OpenDevice(strID, SC.DMORIENT_LANDSCAPE);
        }

        // start SBS mode
        if (nres == SC.SM_SUCCESS && bUseSBS) {
            nres = SD.jSmartComm_SBSStart(SD.handle);
        }

        // insert card...
        if (nres == SC.SM_SUCCESS && bUseSBS) {
            nres = SD.jSmartComm_CardIn(SD.handle);
        }

        // open .csd document...
        //	test.csd is a single paged document.
        String szurl = new File(".").getAbsolutePath();
        szurl = szurl + File.separator + "test.csd";

        if (nres == SC.SM_SUCCESS) {
            nres = SD.jSmartComm_OpenDocument(SD.handle, szurl);
        }

        // print to device...
        if (nres == SC.SM_SUCCESS) {
            nres = SD.jSmartDCL_Print(SD.handle, SC.SMART_PRINTSIDE_FRONT);
        }

        // print start front page...
        if (nres == SmartCommConstant.SM_SUCCESS
                && bUseSBS) {
            nres = SD.jSmartComm_DoPrint(SD.handle);
        }

        // close opened document.
        if (nres == SC.SM_SUCCESS) {
            nres = SD.jSmartComm_CloseDocument(SD.handle);
        }
        // eject card
        if (bUseSBS) {
            SD.jSmartComm_CardOut(SD.handle);
        }

        // end SBS mode...
        if (bUseSBS) {
            SD.jSmartComm_SBSEnd(SD.handle);
        }

        // close device...
        if (true) {
            SD.jSmartDCL_CloseDevice(SD.handle);
        }

        if (nres != SC.SM_SUCCESS) {
            ShowDialogBox("ERROR", "ERROR 1004: DCL CSD File Print :" + nres);
            return;
        }
    }                                                      

    private void jCheckBoxSBSModeActionPerformed(java.awt.event.ActionEvent evt) {                                                 
        // TODO add your handling code here:

        if (jCheckBoxSBSMode.isSelected()) {
            bUseSBS = true;
        } else {
            bUseSBS = false;
        }
}                                                

    private void jPrinterComboBoxActionPerformed(java.awt.event.ActionEvent evt) {                                                 
        // TODO add your handling code here:
/*
        if (SmartDriver.NoDevice > 0) {
            SmartDriver.close();
        }
        

        int ret = 0;
        //int nID[] = new int[1];
        //char ID[] = new char[32 * 16];

        SmartPrinterList spl = new SmartPrinterList();
        SmartPrinterInfo devInfo = new SmartPrinterInfo();


        //int ret=0;
         ret = SD.jSmartComm_GetDeviceList(spl);
         SD.NoDevice = spl.n;
       // jTextArea1.setText("The number of Printer = " + Integer.toString(SD.NoDevice) + "\n");

        //ret = SD.jSmartComm_GetDeviceList(nID, ID);
        String[] sid = new String[32];
        System.out.print("Number of Printers = " + spl.n + "\n");
        jPrinterComboBox.removeAllItems();
        for (int i = 0; i < SD.NoDevice; i++) {
           // sid = new String([i], i * 16, 16);
            //sid[i] = new String(spl.id[i], 0, 16);
            //sid[i] = SD.CopyUntilNullOrSpace(sid[i]);
            sid[i] = SD.CopyUntilNull(spl.id[i]);
            jPrinterComboBoxAddItem(sid[i]);
            System.out.print("Printer ID[" + i + "] = " + sid[i] + "\n");
            //jTextArea1.setText("Printer ID[" + i + "] = " + sid[i] + "\n");
        }
 * 
 */

    }                                                

    private void jPrinterComboBoxMouseClicked(java.awt.event.MouseEvent evt) {                                              
        // TODO add your handling code here:
    }                                             

    private void jPrinterComboBoxItemStateChanged(java.awt.event.ItemEvent evt) {                                                  
        // TODO add your handling code here:
        int ret = 0;
        ret = jPrinterComboBox.getSelectedIndex();




        //ret = SD.jSmartComm_GetDeviceList(nID, ID);
        String[] sid = new String[32];
   //     System.out.print("Number of Printers = " + spl.n + "\n");
    //    jPrinterComboBox.removeAllItems();
        for (int i = 0; i < SD.NoDevice; i++) {
           // sid = new String([i], i * 16, 16);
            //sid[i] = new String(spl.id[i], 0, 16);
            //sid[i] = SD.CopyUntilNullOrSpace(sid[i]);
 //           sid[i] = SD.CopyUntilNull(spl.id[i]);
  //          jPrinterComboBoxAddItem(sid[i]);
            System.out.print("Printer ID[" + i + "] = " + sid[i] + "\n");
            //jTextArea1.setText("Printer ID[" + i + "] = " + sid[i] + "\n");
        }
    }                                                 
    /*
     * #define	DEV_IC					INTERNALDEV
    #define	DEV_SIM					EXTERNALDEV
    #define	DEV_INTERNALRF			INTERNALDEV
    #define	DEV_EXTERNALRF			EXTERNALDEV
     *//**/
    static void jPrinterComboBoxAddItem(String Item) {

        // TODO add your handling code here:
        jPrinterComboBox.addItem(Item);
           }

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) throws IOException {

        new SmartCommonTest4Java().setVisible(true);

        SmartDriver.init();


 
        int ret = 0;


    }

    public static void ShowDialogBox(String Msg, String OKMsg) {
        javax.swing.JFrame jFrame = new JFrame(Msg);
        JTextArea button = new JTextArea(OKMsg);
        jFrame.add(button);
        jFrame.setSize(400, 400);
        jFrame.setVisible(true);
        jFrame.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);

    }

    public static String hex(final int value, final int length) {
        StringBuilder str = new StringBuilder(Integer.toString(value, 16).toUpperCase());
        if (str.length() < length) {
            int falta = (length - str.length());
            for (int i = 1; i <= falta; i++) {
                str.insert(0, "0");
            }
        } else if (str.length() > length) {
            str = new StringBuilder();
            for (int i = 1; i <= length; i++) {
                str.append("*");
            }
        }
        return str.toString();
    }

    public static int memcmp(byte[] fr, byte[] to, final int length) {

        for (int i = 0; i < length; i++) {
            if (fr[i] != to[i]) {
                return (fr[i] - to[i]);
            }
        }
        return 0;
    }

    static boolean DCL_MODE = false;
    static inas.smart.SmartDriver SD = new inas.smart.SmartDriver();
    SmartCommConstant SC = new SmartCommConstant();
    boolean bUseSBS = false;
    // Variables declaration - do not modify
    static javax.swing.JButton jButtonCSDFilePrint;
    static javax.swing.JButton jButtonFunctionDrawingPrint;
    static javax.swing.JButton jButtonDirectDrawingPrint;
    static javax.swing.JButton jButtonMagneticWriteAndRead;
    static javax.swing.JButton jButtonGetATR;
    static javax.swing.JButton jButtonContactlessSmartCard;
    static javax.swing.JButton jButtonDCLDriectDrawingPrint;
    static javax.swing.JButton jButtonDCLFunctionDrawingPrint;
    static javax.swing.JButton jButtonDCLCsdFilePrint;
    static javax.swing.JButton jButtonOpenCSDDocument;
    static javax.swing.JButton jButtonCloseCSDDocument;
    static javax.swing.JCheckBox jCheckBoxSBSMode;
    static javax.swing.JComboBox jLocationBox;
    static javax.swing.JComboBox jPrinterComboBox;
    static javax.swing.JLabel jLabel1;
    static javax.swing.JLabel jLabel2;
    static javax.swing.JPanel jPanel1;
    static javax.swing.JPanel jPanel10;
    static javax.swing.JPanel jPanel2;
    static javax.swing.JPanel jPanel3;
    javax.swing.JPanel jPanel4;
    javax.swing.JPanel jPanel5;
    javax.swing.JPanel jPanel6;
    javax.swing.JPanel jPanel7;
    javax.swing.JPanel jPanel8;
    javax.swing.JPanel jPanel9;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTextPane jTextPane1;
    private javax.swing.JTextField jTextField1;
    private javax.swing.JTextPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JTextArea jTextArea1;
    private javax.swing.JLabel jLabel3;
    private org.jdesktop.beansbinding.BindingGroup bindingGroup;
    // End of variables declaration

    final int	DEV_IC		= SC.INTERNALDEV;
   final int	DEV_SIM		= SC.EXTERNALDEV;
    final int	DEV_INTERNALRF	= SC.INTERNALDEV;
    final int	DEV_EXTERNALRF	= SC.EXTERNALDEV;
 /*
    // Variables declaration - do not modify                     
    private javax.swing.JButton jButtonCSDFilePrint;
    private javax.swing.JButton jButtonCloseCSDDocument;
    private javax.swing.JButton jButtonContactlessSmartCard;
    private javax.swing.JButton jButtonDCLCsdFilePrint;
    private javax.swing.JButton jButtonDCLDriectDrawingPrint;
    private javax.swing.JButton jButtonDCLFunctionDrawingPrint;
    private javax.swing.JButton jButtonDirectDrawingPrint;
    private javax.swing.JButton jButtonFunctionDrawingPrint;
    private javax.swing.JButton jButtonGetATR;
    private javax.swing.JButton jButtonMagneticWriteAndRead;
    private javax.swing.JButton jButtonOpenCSDDocument;
    private javax.swing.JCheckBox jCheckBoxSBSMode;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel6;
    private javax.swing.JPanel jPanel7;
    private javax.swing.JPanel jPanel8;
    private javax.swing.JPanel jPanel9;
    private javax.swing.JComboBox jPrinterComboBox;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JTextArea jTextArea1;
    private javax.swing.JTextPane jTextPane1;
    private org.jdesktop.beansbinding.BindingGroup bindingGroup;
    // End of variables declaration                   

     */
}
